from telnetlib import DO

import numpy as np
from manim import *
from numpy import flip, insert
import math

LV, QL, QH, JH = '#75cfb8', '#bbdfc8', '#f0e5d8', '#ffc478'

class p1(ThreeDScene):
    def construct(self):
        # self.camera.frame.save_state()
        # self.add(NumberPlane())
        # self.camera.frame.rotate(13*DEGREES,about_point=[0.0, 0.0, 1.0])
        r = 1.5
        circle=Circle(2*r).shift([0,0,-r]).set_fill(GRAY,0.1)
        cylinder=Cylinder(2*r,3*r).set_fill(GRAY,0.2).next_to(circle,np.array((0.0, 0.0, 1.0)),0)
        s1=Sphere([r,0,0],r).set_color(LV,1)
        s2=Sphere([-r,0,0],r).set_color(LV,1)
        s3=Sphere([0,r,r*np.sqrt(2)],r).set_color(JH,1)
        s4=Sphere([0,-r,r*np.sqrt(2)],r).set_color(JH,1)
        self.add(cylinder,s1,s2,s3,s4)
        self.renderer.camera.light_source.move_to(3 * IN)
        self.set_camera_orientation(phi=75 * DEGREES, theta=50 * DEGREES)
        self.wait()

class p2(ThreeDScene):
    def construct(self):
        # self.camera.frame.save_state()
        # self.add(NumberPlane())
        # self.camera.frame.rotate(13*DEGREES,about_point=[0.0, 0.0, 1.0])
        r = 1.5
        circle=Circle(2*r).shift([0,0,-r]).set_fill(GRAY,0.1)
        cylinder=Cylinder(2*r,3*r).set_fill(GRAY,0.2).next_to(circle,np.array((0.0, 0.0, 1.0)),0)
        s1=Sphere([r,0,0],r).set_color(LV,1)
        s2=Sphere([-r,0,0],r).set_color(LV,1)
        s3=Sphere([0,r,r*np.sqrt(2)],r).set_color(JH,1)
        s4=Sphere([0,-r,r*np.sqrt(2)],r).set_color(JH,1)
        self.add(cylinder,s1,s2,s3,s4)
        self.renderer.camera.light_source.move_to(3 * IN)
        self.set_camera_orientation(phi=75 * DEGREES, theta=50 * DEGREES)
        # p2
        a=s1.get_center()
        b=s3.get_center()
        ab=Line(a,b)
        c=a+np.array([0,0,r*np.sqrt(2)])
        ca=Line(c,a)
        cb=Line(c,b)
        self.add(ab,ca,cb)
        self.wait()

class p3(MovingCameraScene):
    def construct(self):
        # self.camera.frame.save_state()
        # self.add(NumberPlane())
        # self.camera.frame.rotate(13*DEGREES,about_point=[0.0, 0.0, 1.0])
        r=1.5
        circle=Circle(r*2).set_color(GRAY)
        c1=Circle(r).set_color(LV).shift(LEFT*r)
        c2=Circle(r).set_color(LV).shift(RIGHT*r)
        c3=Circle(r).set_color(JH).shift(UP*r)
        c4=Circle(r).set_color(JH).shift(DOWN*r)
        s=Square(r*2)
        a=c1.get_center()
        b=c4.get_center()
        ab=Line(a,b)
        self.add(circle,c1,c2,c3,c4,s,ab,
                 MathTex('A').next_to(a,LEFT),
                 MathTex('B').next_to(b,DOWN)
                 )

class p4(MovingCameraScene):
    def construct(self):
        # self.camera.frame.save_state()
        # self.add(NumberPlane())
        # self.camera.frame.rotate(13*DEGREES,about_point=[0.0, 0.0, 1.0])
        r=1.5
        c1=Circle(r).set_color(LV).shift(DOWN*r)
        c3=Circle(r).set_color(JH).shift(LEFT*r+UP*r*np.sqrt(2)+DOWN*r)
        c4=Circle(r).set_color(JH).shift(RIGHT*r+UP*r*np.sqrt(2)+DOWN*r)
        s=Square(r*4).set_color(GRAY)
        a=c1.get_center()
        b=c4.get_center()
        aa=Line(a,a+DOWN*r)
        bb=Line(b,b+UP*r)
        a_,b_=a+RIGHT*r,b+LEFT*r
        ab_=DashedLine(a,b_)
        ba_=DashedLine(b,a_)
        aa_=DashedLine(a,a_)
        bb_=DashedLine(b,b_)
        self.add(c1,c3,c4,s,aa,bb,ab_,ba_,aa_,bb_,
                 )